package demo.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HomeController {
	
	@RequestMapping({"/home"})
	public String home(){
		return "home";
	}
	
	@RequestMapping({"/go","/view/go"})
	public String go(String view){
		if(view!=null){
			view = view.trim();
		}
		if(view==null || view.isEmpty()){
			throw new RuntimeException("view is blank");
		}
		
		return view;
	}
	
	
	@RequestMapping({"/go2","/view/go2"})
	public ModelAndView go2(String view,HttpServletRequest request){
		if(view!=null){
			view = view.trim();
		}
		if(view==null || view.isEmpty()){
			throw new RuntimeException("view is blank");
		}
		ModelAndView mv = new ModelAndView();
		mv.setViewName(view);
		mv.addObject("now", new Date()+"");
		mv.addObject("servletPath", request.getServletPath());
		mv.addObject("requestURI", request.getRequestURI());
		mv.addObject("requestURL", request.getRequestURL());
		mv.addObject("queryString", request.getQueryString());

		return mv;
	}
		
}